<!-- 报名登记 -->
<template>
  <div class="trade-info-page">
    <el-row type="flex" justify="center">
      <el-col class="middle-content">
        <div style="height:140px"></div>
        <!-- 面包屑导航 -->
        <el-row class="breadcrumb-nav" type="flex" align="middle">
          <div class="current-place">当前位置：</div>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/propsTrade' }">资产交易</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/propsTrade/tradeinfo' }">交易详情</el-breadcrumb-item>
            <el-breadcrumb-item>报名登记</el-breadcrumb-item>
          </el-breadcrumb>
        </el-row>
        <!-- 内容区 -->
        <el-row class="main-content">
          <!-- 项目信息 -->
          <el-row>
            <el-row class="title">项目信息</el-row>
            <el-row type="flex" class="project-row">
              <el-col class="bgc" :span="4">项目名称</el-col>
              <el-col :span="8">{{propertyInfo.propertyName}}</el-col>
              <el-col class="bgc" :span="4">项目编号</el-col>
              <el-col :span="8">{{propertyInfo.propertyNo}}</el-col>
            </el-row>
            <el-row type="flex" class="project-row" style="border-top: unset;">
              <el-col class="bgc" :span="4">保证金（万元）</el-col>
              <el-col :span="8">{{propertyInfo.earnestMoney}}</el-col>
              <el-col class="bgc" :span="4">挂牌金额（万元）</el-col>
              <el-col :span="8">{{propertyInfo.listingPrice}}</el-col>
            </el-row>
            <el-row type="flex" class="project-row" style="border-top: unset;">
              <el-col class="bgc" :span="4">交易条件</el-col>
              <el-col :span="20">
                <p v-html="propertyInfo.tradingInstruction"></p>
              </el-col>
            </el-row>
          </el-row>
          <!-- 联系人信息 -->
          <el-form ref="form" :rules="rules" :show-message="false" :model="formData">
            <el-row>
              <el-row class="title" style="padding-top:30px">联系人信息</el-row>
              <el-row type="flex" class="project-row">
                <el-col class="bgc" :span="4">联系人名称</el-col>
                <el-col :span="8" class="flex_ai_c">
                  <el-form-item prop="name">
                    <el-input v-model="formData.contactsName" placeholder="请输入联系人名称"></el-input>
                  </el-form-item>
                </el-col>
                <el-col class="bgc" :span="4">联系人电话</el-col>
                <el-col :span="8" class="flex_ai_c">
                  <el-form-item prop="phone">
                    <el-input v-model="formData.contactsPhone" placeholder="请输入联系电话"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex" class="project-row" style="border-top: unset;">
                <el-col class="bgc" :span="4">证件号</el-col>
                <el-col :span="8" class="flex_ai_c">
                  <el-form-item prop="code">
                    <el-input v-model="formData.idNo" placeholder="请输入证件号"></el-input>
                  </el-form-item>
                </el-col>
                <el-col class="bgc" :span="4">联系人地址</el-col>
                <el-col :span="8" class="flex_ai_c">
                  <el-form-item prop="address">
                    <el-input v-model="formData.contactsAddress" placeholder="请输入内容"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-row>
            <!-- 公告内容 -->
            <el-row class="checkbox" type="flex" justify="center">
              <el-form-item>
                <el-checkbox v-model="checked">我已知悉并接受公告所有内容</el-checkbox>
              </el-form-item>
            </el-row>
            <el-row type="flex" justify="center">
              <el-form-item>
                <div class="btn" @click="submit('form')">确认</div>
              </el-form-item>
            </el-row>
          </el-form>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
let ErrInfo = {name: '名称', phone: '手机号', code: '证件号', address: '地址'}

import {signProperty} from '@/api/propsTrade'
import {getStore} from '@/utils/store'
import {validateRules} from '@/utils/validateRules'
export default {
  name: 'tradeEnroll',
  components: {},
  data() {
    return {
      ErrInfo,
      propertyInfo: null,
      checked: true,
      formData: {
        contactsName: '',
        contactsPhone: '',
        idNo: '',
        contactsAddress: '',
        propertyId: ''
      },
      rules: {
        contactsName: [
          {required: true, message: '请输入真实姓名', trigger: 'blur'},
          {min: 2, max: 5, message: '长度在 2 到 10 个字符', trigger: 'blur'},
          {
            required: true,
            pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,
            message: '不支持特殊字符',
            trigger: 'blur'
          }
        ],
        contactsPhone: [{validator: validateRules.phoneNumber, trigger: 'blur'}],
        idNo: [{validator: validateRules.idNo, trigger: 'blur'}],
        contactsAddress: [
          {required: true, message: '请输入地址', trigger: 'blur'},
          {min: 2, max: 5, message: '长度在 2 到 10 个字符', trigger: 'blur'}
        ]
      }
    }
  },
  computed: {},
  watch: {},
  methods: {
    submit(formName) {
      const _this = this
      if (_this.checked) {
        _this.$refs[formName].validate((valid, object) => {
          if (valid) {
            signProperty(Object.assign({}, _this.formData, {propertyId: _this.propertyInfo.id})).then(res => {
              let {
                status,
                data: {code, message, success}
              } = res
              if (status == 200 && code == 500 && !success) {
                this.$message.error(message)
                this.$router.push({path: '/profiles', query: {navIndex: 1}})
              } else if (status == 200 && code == 200 && success) {
                this.$message.success(message)
                this.$router.push({path: '/profiles', query: {navIndex: 1}})
              }
            })
          } else {
            let arr = []
            let ErrList = Object.keys(object)
            ErrList.forEach(item => {
              arr.push(this.ErrInfo[item])
            })
            let str = arr.join('、')
            _this.$message.error(`请填写${str}等必要信息`)
          }
        })
      } else {
        _this.$message.error('请先勾选')
      }
    }
  },
  created() {
    this.propertyInfo = null
    this.propertyInfo = getStore({name: 'PROPERTY_INFO'})
  },
  mounted() {}
}
</script>

<style lang='less' scoped>
.el-form-item {
  margin-bottom: unset;
}

.main-content {
  margin-bottom: 30px;
}
.btn {
  margin-top: 20px;
  width: 420px;
  height: 50px;
  background: #0078e8;
  border-radius: 5px;

  font-size: 18px;
  line-height: 50px;
  color: #ffffff;
  text-align: center;
}
.checkbox {
  margin-top: 20px;
}
.title {
  font-size: 16px;
  font-weight: bold;
  color: #222222;
  line-height: 36px;
}
.project-row {
  border-top: 1px solid #ececec;
  border-bottom: 1px solid #ececec;
  font-size: 14px;
  color: #222222;
  line-height: 48px;
  .bgc {
    background-color: #f9f9f9;
  }
  .el-col {
    box-sizing: border-box;
    padding-left: 20px;
    padding-right: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.main-content {
  padding: 60px 80px;
  background-color: #fff;
}
// 面包屑导航
.breadcrumb-nav {
  font-size: 14px;
  color: #666666;
  line-height: 24px;
  padding: 24px 0 32px 0;
}
</style>